<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<title>Pay Demo</title> 
<script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="../js/jweixin-1.2.0.js"></script>
<script type="text/javascript" src="../js/wx.js"></script>
</head>  
<script>
  function Pay()
  {
	   $.ajax({
          url:"/zhaowj/PayServlet"
		  
	  }).done(function(data){
		   var obj=eval('('+data+')');
			if(parseInt(obj.agent)<5)
			{
				 alert("您的微信版本过低，请更新！")
				 return;
			}
			WeixinJSBridge.invoke('getBrandWCPayRequest',{
           "appId":obj.appId,     //公众号名称，由商户传入     
           "timeStamp":obj.timeStamp,         //时间戳，自1970年以来的秒数     
           "nonceStr":obj.nonceStr, //随机串     
           "package":obj.packageValue,     
           "signType":obj.signType,         //微信签名方式：     
           "paySign":obj.paySign //微信签名 
       },function(res){
		   alert(res.err_msg);
		   if(res.err_msg == "get_brand_wcpay_request：ok" ) {
			   window.location.href=obj.sendUrl;
		   }else{
				alert("错误");
				
		   }
	   });
		  
	  });
  }
	 
</script> 
<body>
<br/><br/>
<br/><br/>
<input type="button" id="btnpay" onclick="Pay()" value="给钱"/>
<div id="contentDiv">
</div>
</body>
</html>